home *** CD-ROM | disk | FTP | other *** search
/ Internet Info 1997 December / Internet_Info_CD-ROM_Walnut_Creek_December_1997.iso / faqs / gnu / gpp / help / FAQ_for_g++_and_libg++,_plain_text_version__[Revised_01_Oct_1997] < prev    next >
Internet Message Format  |  1997-10-02  |  73KB

  1. Path: senator-bedfellow.mit.edu!bloom-beacon.mit.edu!nntprelay.mathworks.com!newsfeed.internetmci.com!199.0.154.56!ais.net!uunet!in5.uu.net!aesop.synopsys.com!news.synopsys.com!jbuck
  2. From: jbuck@synopsys.com (Joe Buck)
  3. Newsgroups: gnu.g++.help,comp.lang.c++,news.answers,comp.answers
  4. Subject: FAQ for g++ and libg++, plain text version  [Revised 01 Oct 1997]
  5. Supersedes: <g++-FAQ_09_15_1997_texi@synopsys.com>
  6. Followup-To: poster
  7. Date: 1 Oct 1997 13:00:08 GMT
  8. Organization: Synopsys, Inc.
  9. Lines: 1682
  10. Approved: news-answers-request@MIT.edu
  11. Expires: 1 Nov 1997 00:00:00 GMT
  12. Message-ID: <g++-FAQ_10_01_1997_texi@synopsys.com>
  13. NNTP-Posting-Host: atrus.synopsys.com
  14. Originator: jbuck@atrus
  15. Xref: senator-bedfellow.mit.edu gnu.g++.help:18645 comp.lang.c++:284086 news.answers:113565 comp.answers:28319
  16.  
  17. Archive-name: g++-FAQ/plain
  18. Last-modified: 01 Oct 1997
  19. Frequency: bimonthly
  20.  
  21. [ this is the plain text version, the parent is the texinfo version ]
  22.  
  23.  
  24. FAQ for g++ and libg++, by Joe Buck (jbuck@synopsys.com)
  25. ********************************************************
  26.  
  27.    This is a list of frequently asked questions (FAQ) for g++ users;
  28. thanks to all those who sent suggestions for improvements.  Thanks to
  29. Marcus Speh for doing the index.  A hypertext version is available on
  30. the World Wide Web at `http://www.cygnus.com/misc/g++FAQ_toc.html'.
  31.  
  32.    This document has just been reorganized a bit.  There is some new
  33. information about upcoming g++ releases and egcs; more needs to be done
  34. but that will need to wait for next time.  A diff would look
  35. misleadingly large, since I blew away and rebuilt the texinfo menus.
  36.  
  37.    Please send updates and corrections to the FAQ to
  38. `jbuck@synopsys.com'.  Please do *not* use me as a resource to get your
  39. questions answered; that's what `gnu.g++.help' is for and I don't have
  40. the time to support the net's use of g++.
  41.  
  42.    Many FAQs, including this one, are available on the archive site
  43. "rtfm.mit.edu"; see
  44. `ftp://rtfm.mit.edu/pub/usenet/news.answers'.  This FAQ may be found in
  45. the subdirectory g++-FAQ.
  46.  
  47.    This FAQ is intended to supplement, not replace, Marshall Cline's
  48. excellent FAQ for the C++ language and for the newsgroup
  49. `comp.lang.c++'.  Especially if g++ is the first C++ compiler you've
  50. ever used, the question "How do I do <X> with g++?" is probably really
  51. "How do I do <X> in C++?".  You can find this FAQ at
  52. `ftp://rtfm.mit.edu/pub/usenet/comp.lang.c++', or in HTML form at
  53. `http://www.cerfnet.com/~mpcline/On-Line-C++-FAQs/'.
  54.  
  55. The basics: what is g++?
  56. ************************
  57.  
  58.    g++ is the traditional nickname of GNU C++, a freely redistributable
  59. C++ compiler produced by the Free Software Foundation plus dozens of
  60. skilled volunteers.  I say "traditional nickname" because the GNU
  61. compiler suite, gcc, bundles together compilers for C, Objective-C, and
  62. C++ in one package.
  63.  
  64.    While the source code to gcc/g++ can be downloaded for free, it is
  65. not public domain, but is protected by the GNU Public License, or GPL
  66. (*note legalities::.).
  67.  
  68. What is the latest version of gcc, g++, and libg++?
  69. ===================================================
  70.  
  71.    The current version of gcc/g++ is 2.7.2.3, released August 20, 1997.
  72. Although that looks very recent, the only change is a minor patch to
  73. resolve a problem with Linux and the GNU C library; users not interested
  74. in that functionality have no reason to upgrade.
  75.  
  76.    The current version of libg++ is 2.7.2, released July 4, 1996.  The
  77. last release of gcc/g++ with improvements to the C++ front end was
  78. 2.7.2, released Nov. 25, 1995, nearly two years ago.
  79.  
  80.    I would strongly recommend that anyone using a g++ version earlier
  81. than 2.7.2 should upgrade if at all possible (*note version 2.7.x::.).
  82.  
  83.    For some non-Unix platforms, the latest port of gcc may be an earlier
  84. version (2.6.3, say).  You'll need to use a version of libg++ that has
  85. the same first two digits as the compiler version, e.g. use libg++
  86. 2.6.x (for the latest x you can find) with gcc version 2.6.3.
  87.  
  88.    The latest "1.x" version of gcc is 1.42, and the latest "1.x"
  89. version of g++ is 1.42.0.  While gcc 1.42 is quite usable for C
  90. programs, I recommend against using g++ 1.x except in special
  91. circumstances (and I can't think of any such circumstances).
  92.  
  93. How do I get a copy of g++ for Unix?
  94. ====================================
  95.  
  96.    First, you may already have it if you have gcc for your platform;
  97. g++ and gcc are combined now (as of gcc version 2.0).
  98.  
  99.    You can get g++ from a friend who has a copy, by anonymous FTP or
  100. UUCP, or by ordering a tape or CD-ROM from the Free Software Foundation.
  101.  
  102.    The Free Software Foundation is a nonprofit organization that
  103. distributes software and manuals to raise funds for more GNU
  104. development.  Getting your copy from the FSF contributes directly to
  105. paying staff to develop GNU software.  CD-ROMs cost $400 if an
  106. organization is buying, or $100 if an individual is buying.  Tapes cost
  107. around $200 depending on media type.  I recommend asking for version 2,
  108. not version 1, of g++.
  109.  
  110.    For more information about ordering from the FSF, contact
  111. gnu@prep.ai.mit.edu, phone (617) 542-5942 or anonymous ftp file
  112. `ftp://prep.ai.mit.edu/pub/gnu/GNUinfo/ORDERS' (you can also use one of
  113. the sites listed below if you can't get into "prep").
  114.  
  115.    Here is a list of anonymous FTP archive sites for GNU software.  If
  116. no directory is given, look in `/pub/gnu'.
  117.  
  118.      ASIA: ftp.cs.titech.ac.jp, tron.um.u-tokyo.ac.jp:/pub/GNU/prep
  119.      cair-archive.kaist.ac.kr, ftp.nectec.or.th:/pub/mirrors/gnu
  120.      
  121.      AUSTRALIA: archie.au:/gnu (archie.oz or archie.oz.au for ACSnet)
  122.      
  123.      AFRICA: ftp.sun.ac.za
  124.      
  125.      MIDDLE-EAST: ftp.technion.ac.il:/pub/unsupported/gnu
  126.      
  127.      EUROPE: irisa.irisa.fr, ftp.univ-lyon1.fr,
  128.      ftp.mcc.ac.uk, unix.hensa.ac.uk:/mirrors/uunet/systems/gnu,
  129.      src.doc.ic.ac.uk:/gnu, ftp.ieunet.ie, ftp.eunet.ch,
  130.      nic.switch.ch:/mirror/gnu, ftp.informatik.rwth-aachen.de,
  131.      ftp.informatik.tu-muenchen.de, ftp.win.tue.nl, ftp.nl.net,
  132.      ftp.etsimo.uniovi.es, ftp.funet.fi, ftp.denet.dk,
  133.      ftp.stacken.kth.se, isy.liu.se, ftp.luth.se:/pub/unix/gnu,
  134.      ftp.sunet.se, archive.eu.net
  135.      
  136.      SOUTH AMERICA: ftp.inf.utfsm.cl, ftp.unicamp.br
  137.      
  138.      WESTERN CANADA: ftp.cs.ubc.ca:/mirror2/gnu
  139.      
  140.      USA: wuarchive.wustl.edu:/systems/gnu, labrea.stanford.edu,
  141.      ftp.digex.net, ftp.kpc.com:/pub/mirror/gnu, f.ms.uky.edu:/pub3/gnu,
  142.      jaguar.utah.edu:/gnustuff, ftp.hawaii.edu:/mirrors/gnu,
  143.      uiarchive.cso.uiuc.edu, ftp.cs.columbia.edu:/archives/gnu/prep,
  144.      gatekeeper.dec.com:/pub/GNU, ftp.uu.net:/systems/gnu
  145.  
  146.    The "official site" is prep.ai.mit.edu, but your transfer will
  147. probably go faster if you use one of the above machines.
  148.  
  149.    Most GNU utilities are compressed with "gzip", the GNU compression
  150. utility.  All GNU archive sites should have a copy of this program,
  151. which you will need to uncompress the distributions.
  152.  
  153.    Don't forget to retrieve libg++ as well!
  154.  
  155. Getting gcc/g++ for the HP Precision Architecture
  156. =================================================
  157.  
  158.    If you use the HP Precision Architecture (HP-9000/7xx and
  159. HP-9000/8xx) and you want to use debugging, you'll need to use the GNU
  160. assembler, GAS (version 2.3 or later).  If you build from source, you
  161. must tell the configure program that you are using GAS or you won't get
  162. debugging support.  A non-standard debug format is used, since until
  163. recently HP considered their debug format a trade secret.  Thanks to
  164. the work of lots of good folks both inside and outside HP, the company
  165. has seen the error of its ways and has now released the required
  166. information.  The team at the University of Utah that did the gcc port
  167. now has code that understands the native HP format.
  168.  
  169.    There are binaries for GNU tools in `ftp://jaguar.cs.utah.edu/dist/',
  170. but these are older versions.
  171.  
  172.    Jeff Law has left the University of Utah, so the Utah prebuilt
  173. binaries may be discontinued.
  174.  
  175. Getting gcc/g++ binaries for Solaris 2.x
  176. ========================================
  177.  
  178.    "Sun took the C compiler out of Solaris 2.x.  Am I stuck?"
  179.  
  180.    You'll need to get prebuilt binaries from someone.
  181.  
  182.    It used to be that you could get GCC binaries from prep.ai.mit.edu;
  183. these are no longer there.
  184.  
  185.    The WWW site `http://smc.vnet.net/solaris_2.5.html' contains various
  186. GNU and freeware programs for Solaris2.5 running on the sparc. These are
  187. packaged to enable easy installation using the Solaris "pkgadd" utility.
  188. These include GNU emacs, gcc, gdb, perl, and others.  These versions
  189. are more recent than the binaries at "prep" (gcc 2.7.2 and libg++ 2.7.1
  190. are there).
  191.  
  192. How do I get a copy of g++ for (some other platform)?
  193. =====================================================
  194.  
  195.    As of gcc-2.7.x, there is Windows NT support in gcc.  Some special
  196. utilities are required.  See the INSTALL file from the distribution.
  197. If you're interested in GNU tools on Windows NT, see
  198. `http://www.cygnus.com/misc/gnu-win32/' on the WWW, or the anonymous
  199. FTP directory `ftp://ftp.cygnus.com/pub/gnu-win32/'.
  200.  
  201.    The standard gcc/g++ distribution includes VMS support for the Vax.
  202. Since the FSF people don't use VMS, it's likely to be somewhat less
  203. solid than the Unix version.  Precompiled copies of g++ and libg++ in
  204. VMS-installable form for the Vax are available by FTP from
  205. `ftp://mango.rsmas.miami.edu/pub/VMS-gcc/'.
  206.  
  207.    Klaus Kaempf (kkaempf@progis.de) has done a port to OpenVMS for the
  208. Alpha; this is not yet a part of the official gcc/g++.  The port
  209. includes g++ and all libraries from the libg++ distribution.  See
  210. `http://www.progis.de' for more details.
  211.  
  212.    There are two different versions of gcc/g++ for MS-DOS: EMX and
  213. DJGPP.  EMX also works for OS/2 and is described later.  DJGPP is DJ
  214. Delorie's port.  It can be found on many FTP archive sites; try
  215. `ftp://ftp.coast.net/SimTel/vendors/djgpp/' or, for a complete list, see
  216. `http://www.delorie.com/djgpp/getting.html'.
  217.  
  218.    The latest version of DJGPP is 2.00.  See
  219. `http://www.delorie.com/djgpp/v2/' for information on this version.
  220.  
  221.    FSF sells floppies with DJGPP on them; see above for ordering
  222. software from the FSF.
  223.  
  224.    DJGPP has its own newsgroup: `comp.os.msdos.djgpp'.
  225.  
  226.    Development and porting efforts for GNU tools, including gcc/g++, for
  227. the Amiga are maintained by an initiative named ADE (Amiga Developers
  228. Environment.  More information about ADE is available at
  229. `http://www.ninemoons.com/'.
  230.  
  231.    For more information on Amiga ports of gcc/g++, retrieve the file
  232. `ftp://prep.ai.mit.edu/pub/gnu/MicrosPorts/Amiga'.
  233.  
  234.    A port of gcc to the Atari ST can be found at
  235. `ftp://atari.archive.umich.edu/atari/Gnustuff/Tos' along with many
  236. other GNU programs.  This version is usually the same as the latest FSF
  237. release.  See the "Software FAQ" for the Usenet group
  238. `comp.sys.atari.st' for more information.
  239.  
  240.    EMX is a port of gcc to OS/2; it can also be used on MS-DOS.  In
  241. addition to the compiler port, the EMX port's C library attempts to
  242. provide a Unix-like environment.  For more information ask around on
  243. `comp.os.os2.programmer.porting'.  Version 0.9c, based on gcc-2.7.2.1,
  244. was released in November 1996.  It is available by FTP and the WWW
  245. from, among other places
  246.  
  247.      `http://www.os2ss.com/unix/emx09c/'
  248.      `ftp://ftp.cdrom.com/pub/os2/emx09c/' (US)
  249.      `ftp://ftp.leo.org/pub/comp/os/os2/leo/devtools/emx+gcc/' (Germany)
  250.  
  251.    Eberhard Mattes did the EMX port.  His address is
  252. mattes@azu.informatik.uni-stuttgart.de.  Read the FAQ file included
  253. with the distribution before harrassing the author.
  254.  
  255.    I'm looking for more information on gcc/g++ support on the Apple
  256. Macintosh.  Until recently, this FAQ did not provide such information,
  257. but FSF is no longer boycotting Apple as the League for Programming
  258. Freedom boycott has been dropped.
  259.  
  260.    Versions 1.37.1 and 2.3.3 of gcc were ported by Stan Shebs and are
  261. available at
  262. `ftp://ftp.cygnus.com/pub/mac'
  263.  
  264.    They are both interfaced to MPW.  Stan is working on a version using
  265. the current (post-2.7) sources, contact him directly (shebs@cygnus.com)
  266. for more information.
  267.  
  268. But I can only find g++-1.42!
  269. =============================
  270.  
  271.    "I keep hearing people talking about g++ 2.7.2 (or some other number
  272. starting with 2), but the latest version I can find is g++ 1.42.  Where
  273. is it?"
  274.  
  275.    As of gcc 2.0, C, C++, and Objective-C as well are all combined into
  276. a single distribution called gcc.  If you get gcc you already have g++.
  277. The standard installation procedure for any gcc version 2 compiler will
  278. install the C++ compiler as well.
  279.  
  280.    One could argue that we shouldn't even refer to "g++-2.x.y" but it's
  281. a convention.  It means "the C++ compiler included with gcc-2.x.y."
  282.  
  283. Installation Issues and Problems
  284. ********************************
  285.  
  286. I can't build g++ 1.x.y with gcc-2.x.y!
  287. =======================================
  288.  
  289.    "I obtained gcc-2.x.y and g++ 1.x.y and I'm trying to build it, but
  290. I'm having major problems.  What's going on?"
  291.  
  292.    If you wish to build g++-1.42, you must obtain gcc-1.42 first.  The
  293. installation instructions for g++ version 1 leave a lot to be desired,
  294. unfortunately, and I would recommend that, unless you have a special
  295. reason for needing the 1.x compiler, that C++ users use the latest
  296. g++-2.x version, as it is the version that is being actively maintained.
  297.  
  298.    There is no template support in g++-1.x, and it is generally much
  299. further away from the ANSI draft standard than g++-2.x is.
  300.  
  301. OK, I've obtained gcc; what else do I need?
  302. ===========================================
  303.  
  304.    First off, you'll want libg++ as you can do almost nothing without it
  305. (unless you replace it with some other class library).
  306.  
  307.    Second, depending on your platform, you may need "GAS", the GNU
  308. assembler, or the GNU linker (see next question).
  309.  
  310.    Finally, while it is not required, you'll almost certainly want the
  311. GNU debugger, gdb.  The latest version is 4.16, released April 22, 1996.
  312. Other debuggers (like dbx, for example) will normally not be able to
  313. understand at least some of the debug information produced by g++.
  314.  
  315. Should I use the GNU linker, or should I use "collect"?
  316. =======================================================
  317.  
  318.    First off, for novices: special measures must be taken with C++ to
  319. arrange for the calling of constructors for global or static objects
  320. before the execution of your program, and for the calling of
  321. destructors at the end.  (Exception: System VR3 and System VR4 linkers,
  322. Linux/ELF, and some other systems support user-defined segments; g++ on
  323. these systems requires neither the GNU linker nor collect.  So if you
  324. have such a system, the answer is that you don't need either one,
  325. though using GNU ld does have some advantages over the native linker in
  326. some cases).
  327.  
  328.    If you have experience with AT&T's "cfront", this function is
  329. performed there by programs named "patch" or "munch".  With GNU C++, it
  330. is performed either by the GNU linker or by a program known as
  331. "collect".  The collect program is part of the gcc-2.x distribution;
  332. you can obtain the GNU linker separately as part of the "binutils"
  333. package.  The latest version of binutils is 2.7, released July 10,
  334. 1996; 2.6 is in common use and works well.
  335.  
  336.    (To be technical, it's "collect2"; there were originally several
  337. alternative versions of collect, and this is the one that survived).
  338.  
  339.    There are advantages and disadvantages to either choice.
  340.  
  341.    Advantages of the GNU linker:
  342.  
  343.    It's faster than using collect - collect basically runs the standard
  344. Unix linker on your program twice, inserting some extra code after the
  345. first pass to call the constructors.  This is a sizable time penalty
  346. for large programs.  The GNU linker does not require this extra pass.
  347.  
  348.    GNU ld reports undefined symbols using their true names, not the
  349. mangled names (but as of 2.7.0 so does collect).
  350.  
  351.    If there are undefined symbols, GNU ld reports which object file(s)
  352. refer to the undefined symbol(s).  On some OSes (e.g. SunOS, Solaris)
  353. the native linker does not do this, so you have to track down who's
  354. referring to the missing symbols yourself.
  355.  
  356.    As of binutils version 2.2, on systems that use the so-called "a.out"
  357. debug format (e.g. Suns running SunOS 4.x), the GNU linker compresses
  358. the debug symbol table considerably.  The 2.7 version adds some symbol
  359. table compression for ELF and Solaris targets.
  360.  
  361.    Advantages of collect:
  362.  
  363.    If your native linker supports shared libraries, you can use shared
  364. libraries with collect.  This used to be a strong reason *not* to use
  365. the GNU linker, but recent versions of GNU ld support linking with
  366. shared libraries on many platforms, and creating shared libraries on a
  367. few (such as Intel x86 systems that use ELF object format as well as
  368. SunOS and Solaris).
  369.  
  370.    *Note shared libraries::
  371.  
  372.    The GNU linker has not been ported to as many platforms as g++ has,
  373. so you may be forced to use collect.
  374.  
  375.    If you use collect, you don't need to get something extra and figure
  376. out how to install it; the standard gcc installation procedure will do
  377. it for you.
  378.  
  379.    I used to say at this point that I don't see a clear win for either
  380. linking alternative, but with all the improvements in the GNU linker I
  381. think that it is now the better choice.  Take your pick.
  382.  
  383.    If you run Linux, the only available linker is the GNU linker.
  384.  
  385. Should I use the GNU assembler, or my vendor's assembler?
  386. =========================================================
  387.  
  388.    This depends on your platform and your decision about the GNU
  389. linker.  For most platforms, you'll need to use GAS if you use the GNU
  390. linker.  For some platforms, you have no choice; check the gcc
  391. installation notes to see whether you must use GAS.  But you can
  392. usually use the vendor's assembler if you don't use the GNU linker.
  393.  
  394.    The GNU assembler assembles faster than many native assemblers;
  395. however, on many platforms it cannot support the local debugging format.
  396.  
  397.    It used to be that the GNU assembler couldn't handle
  398. position-independent code on SunOS.  This is no longer true if you have
  399. version 2.6 or newer.
  400.  
  401.    On HPUX or IRIX, you must use GAS (and configure gcc with the
  402. `--with-gnu-as' option) to debug your programs.  GAS is strongly
  403. recommended particularly on the HP platform because of limitations in
  404. the HP assembler.
  405.  
  406.    The GNU assembler has been merged with the binutils distribution, so
  407. the GNU assembler and linker are now together in this package (as of
  408. binutils version 2.5.1).
  409.  
  410.    On Linux the assembler is the GNU assembler.
  411.  
  412. How do I build shared libraries with g++?
  413. =========================================
  414.  
  415.    For gcc-2.7.0 and later, building C++ shared libraries should work
  416. fine on supported platforms (HPUX 9+, IRIX 5+, DEC UNIX (formerly
  417. OSF/1), SGI/IRIX, AIX, SunOS 4, Linux/ELF and all targets using
  418. SVR4-style ELF shared libraries).  There are two separate issues:
  419. building libg++ as a shared library, and making your own shared
  420. libraries.  For libg++ it is simply a matter of giving the
  421. `--enable-shared' option to the configure program.  When compiling your
  422. own code for shared libraries you generally must use the `-fPIC' flag
  423. to get position-independent code.
  424.  
  425.    If your shared library contains global or static objects with
  426. constructors, then make sure to use `gcc -shared', not `ld', to create
  427. the shared library.  This will make sure that any processor-specific
  428. magic needed to execute the constructors is included.
  429.  
  430.    In theory, constructors for objects in your shared library should be
  431. called when the library is opened (by dlopen or equivalent).  This does
  432. not work on some platforms (e.g. SunOS4; it does work on Solaris and
  433. ELF systems such as Linux): on the broken platforms, the constructors
  434. are not called correctly.
  435.  
  436.    David Nilsen has suggested the following workaround:
  437.  
  438.    The thing to realize is that if you link your dynamic module with the
  439. `-shared' flag, the collect program nicely groups all the static
  440. ctors/dtors for you into a list and sets up a function that will call
  441. them (Note: this means that this trick won't work if you use the GNU
  442. linker without collect (*note use GNU linker?::.).
  443.  
  444.    The magic is knowing these function names.  Currently, they're
  445. called:
  446.  
  447.      _GLOBAL__DI   <-- calls all module constructors
  448.      _GLOBAL__DD   <-- calls all module destructors
  449.  
  450.    [ possibly the leading underscore will differ between platforms:
  451. jbuck ]
  452.  
  453.    Therefore, if you make a wrapper around dlopen that looks up the
  454. symbol `_GLOBAL__DI' (or `__GLOBAL__DI' on SunOS4 machines), and calls
  455. it, you'll simulate getting the constructors called.
  456.  
  457.    You also need to set up the destructors to be called as well, so you
  458. need to put a wrapper around dlclose, which will call the `_GLOBAL__DD'
  459. function in the module when/if it's unloaded.
  460.  
  461.    Lastly, to get things 100% correct, you need to set up the
  462. destructors to also be called if the module is not unloaded, but the
  463. main program exits.  I do this by registering a single function with
  464. `atexit()' that calls all the destructors left in dynamically loaded
  465. modules.
  466.  
  467.    Check the file `README.SHLIB' from the libg++ distribution for more
  468. about making and using shared libraries.
  469.  
  470.    A patch is needed to build shared versions of version 2.7.2 of libg++
  471. and libstdc++ on the HP-PA architecture.  You can find the patch at
  472. `ftp://ftp.cygnus.com/pub/g++/libg++-2.7.2-hppa-gcc-fix'.
  473.  
  474. How do I use the new repository code?
  475. =====================================
  476.  
  477.    Because there is some disagreement about the details of the template
  478. repository mechanism, you'll need to obtain a patch from Cygnus Support
  479. to enable the 2.7.2 repository code.  You can obtain the patch by
  480. anonymous FTP: `ftp://ftp.cygnus.com/pub/g++/gcc-2.7.2-repo.gz'.
  481.  
  482.    There are patches for 2.7.0 and 2.7.1 in the same directory, though
  483. if you're going to rebuild the compiler you should use the latest one.
  484.  
  485.    If you're running NetBSD or BSDI, the Cygnus repo patch is not quite
  486. correct.  Tim Liddelow has made an alternate version available at
  487. `ftp://ftp.cst.com.au/pub/gcc-2.7.2-repo-bsd.gz'.
  488.  
  489.    After you've applied the patch, the `-frepo' flag will enable the
  490. repository mechanism.  The flag works much like the existing
  491. `-fno-implicit-templates' flag, except that auxiliary files, with an
  492. `.rpo' extension, are built that specify what template expansions are
  493. needed.  At link time, the (patched) collect program detects missing
  494. templates and recompiles some of the object files so that the required
  495. templates are expanded.
  496.  
  497.    Note that the mechanism differs from that of cfront in that template
  498. definitions still must be visible at the point where they are to be
  499. expanded.  No assumption is made that `foo.C' contains template
  500. definitions corresponding to template declarations in `foo.h'.
  501.  
  502.    Jason Merrill writes: "To perform closure on a set of objects, just
  503. try to link them together.  It will fail, but as a side effect all
  504. needed instances will be generated in the objects."
  505.  
  506. Known bugs and problems with the repo patch
  507. ===========================================
  508.  
  509.    "The `-frepo' won't expand templated friend functions!"
  510.  
  511.    This is a known bug; currently you'll have to explicitly instantiate
  512. friend functions when using `-frepo' due to this bug (in 2.7.0 through
  513. 2.7.2 at least).
  514.  
  515.    With earlier versions of the repo patch, there was a bug that happens
  516. when you have given a quoted command line switch, something like
  517.  
  518.      -D'MESSAGE="hello there"'
  519.  
  520.    The repo code tries to recompile files using the same flags you
  521. originally specified, but doesn't quote arguments that need quoting,
  522. resulting in failures in some cases.  This is no longer a problem with
  523. the 2.7.2 patch.
  524.  
  525. Should I use the GNU C library?
  526. ===============================
  527.  
  528.    At this point in time, no (unless you are running Linux or the GNU
  529. Hurd system).  The GNU C library is still very young, and libg++ still
  530. conflicts with it in some places.  Use your native C library unless you
  531. know a lot about the gory details of libg++ and gnu-libc.  This will
  532. probably change in the future.
  533.  
  534. Global constructors aren't being called
  535. =======================================
  536.  
  537.    "I've installed gcc and it almost works, but constructors and
  538. destructors for global objects and objects at file scope aren't being
  539. called.  What did I do wrong?"
  540.  
  541.    It appears that you are running on a platform that requires you to
  542. install either "collect2" or the GNU linker, and you have done neither.
  543. For more information, see the section discussing the GNU linker (*note
  544. use GNU linker?::.).
  545.  
  546.    On Solaris 2.x, you shouldn't need a collect program and GNU ld
  547. doesn't run.  If your global constructors aren't being called, you may
  548. need to install a patch, available from Sun, to fix your linker.  The
  549. number of the "jumbo patch" that applies is 101409-03.  Thanks to
  550. Russell Street (r.street@auckland.ac.nz) for this info.
  551.  
  552.    It appears that on IRIX, the collect2 program is not being installed
  553. by default during the installation process, though it is required; you
  554. can install it manually by executing
  555.  
  556.      make install-collect2
  557.  
  558.    from the gcc source directory after installing the compiler.  (I'm
  559. not certain for which versions of gcc this problem occurs, and whether
  560. it is still present).
  561.  
  562. Strange assembler errors when linking C++ programs
  563. ==================================================
  564.  
  565.    "I've installed gcc and it seemed to go OK, but when I attempt to
  566. link any C++ program, I'm getting strange errors from the assembler!
  567. How can that be?"
  568.  
  569.    The messages in question might look something like
  570.  
  571.      as: "/usr/tmp/cca14605.s", line 8: error: statement syntax
  572.      as: "/usr/tmp/cca14605.s", line 14: error: statement syntax
  573.  
  574.    (on a Sun, different on other platforms).  The important thing is
  575. that the errors come out at the link step, *not* when a C++ file is
  576. being compiled.
  577.  
  578.    Here's what's going on: the collect2 program uses the Unix "nm"
  579. program to obtain a list of symbols for the global constructors and
  580. destructors, and it builds a little assembly language module that will
  581. permit them all to be called.  If you're seeing this symptom, you have
  582. an old version of GNU nm somewhere on your path.  This old version
  583. prints out symbol names in a format that the collect2 program does not
  584. expect, so bad assembly code is generated.
  585.  
  586.    The solution is either to remove the old version of GNU nm from your
  587. path (and that of everyone else who uses g++), or to install a newer
  588. version (it is part of the GNU "binutils" package).  Recent versions of
  589. GNU nm do not have this problem.
  590.  
  591. Other problems building libg++
  592. ==============================
  593.  
  594.    "I am having trouble building libg++.  Help!"
  595.  
  596.    On some platforms (for example, Ultrix), you may see errors
  597. complaining about being unable to open dummy.o.  On other platforms
  598. (for example, SunOS), you may see problems having to do with the type
  599. of size_t.  The fix for these problems is to make libg++ by saying
  600. "make CC=gcc".  According to Per Bothner, it should no longer be
  601. necessary to specify "CC=gcc" for libg++-2.3.1 or later.
  602.  
  603.    "I built and installed libg++, but g++ can't find it.  Help!"
  604.  
  605.    The string given to `configure' that identifies your system must be
  606. the same when you install libg++ as it was when you installed gcc.
  607. Also, if you used the `--prefix' option to install gcc somewhere other
  608. than `/usr/local', you must use the same value for `--prefix' when
  609. installing libg++, or else g++ will not be able to find libg++.
  610.  
  611.    The toplevel Makefile in the libg++ 2.6.2 distribution is broken,
  612. which along with a bug in g++ 2.6.3 causes problems linking programs
  613. that use the libstdc++ complex classes.  A patch for this is available
  614. from `ftp://ftp.cygnus.com//pub/g++/libg++-2.6.2-fix.gz'.
  615.  
  616. But I'm *still* having problems with `size_t'!
  617. ==============================================
  618.  
  619.    "I did all that, and I'm *still* having problems with disagreeing
  620. definitions of size_t, SIZE_TYPE, and the type of functions like
  621. `strlen'."
  622.  
  623.    The problem may be that you have an old version of `_G_config.h'
  624. lying around.  As of libg++ version 2.4, `_G_config.h', since it is
  625. platform-specific, is inserted into a different directory; most include
  626. files are in `$prefix/lib/g++-include', but this file now lives in
  627. `$prefix/$arch/include'.  If, after upgrading your libg++, you find that
  628. there is an old copy of `_G_config.h' left around, remove it, otherwise
  629. g++ will find the old one first.
  630.  
  631. Do I need to rebuild libg++ to go with my new g++?
  632. ==================================================
  633.  
  634.    "After I upgraded g++ to the latest version, I'm seeing undefined
  635. symbols."
  636.  
  637.    or
  638.  
  639.    "If I upgrade to a new version of g++, do I need to reinstall
  640. libg++?"
  641.  
  642.    As a rule, the first two digits of your g++ and libg++ should be the
  643. same.  Normally when you do an upgrade in the "minor version number"
  644. (2.5.7 to 2.5.8, say) there isn't a need to rebuild libg++, but there
  645. have been a couple of exceptions in the past.
  646.  
  647. I want several versions of g++ and libg++ to co-exist.
  648. ======================================================
  649.  
  650.    I recommend against using the `-V' flag to make multiple versions of
  651. gcc/g++ co-exist, unless they are different minor releases that can use
  652. the same compiled version of libg++.  The reason is that all these
  653. versions will try to use the same libg++ version, which usually will
  654. not work.
  655.  
  656.    Instead, use the `--prefix' flag when configuring gcc.  Use a
  657. different value of `--prefix' for each gcc version.  Use the same value
  658. of `--prefix' when configuring libg++.  You can then have any number of
  659. co-existing gcc/libg++ pairs.  Symbolic links can be used so that users
  660. don't need to put all these different directories on their paths.
  661.  
  662.    One possible system to use is to set `--prefix' to
  663. `/usr/local/gcc-2.x.y' for version 2.x.y of gcc, and to link whichever
  664. version of gcc you wish to be the default into `/usr/local/bin/gcc' and
  665. `/usr/local/bin/g++'.
  666.  
  667. Trouble installing g++ and libg++ on Linux
  668. ==========================================
  669.  
  670.    "I've downloaded the latest g++ and libg++ and I'm trying to install
  671. them on Linux, and I'm having lots of problems."
  672.  
  673.    FSF releases of libg++ won't install on Linux unchanged, since Linux
  674. uses are part of the libio library from libg++ for its standard C
  675. library, only this is changed in a way that it clashes with libg++.
  676. This means that you'll need a patched version of libg++ for it to work.
  677.  
  678.    If you want to upgrade to a new gcc/libg++ combination, the easiest
  679. thing to do is to grab the prebuilt versions of gcc and libg++ for Linux
  680. from `ftp://tsx-11.mit.edu/pub/linux/packages/GCC'.  Follow the
  681. directions carefully.  If you want to build from source, you'll need a
  682. patch for libg++; the Linux developers have named the patched libg++
  683. version libg++-2.7.1.3 and there is a patch file in the above-named
  684. directory.
  685.  
  686.    See `http://sunsite.unc.edu/LDP/HOWTO/GCC-HOWTO.html', the Linux GCC
  687. HOWTO, for more on gcc/g++ and Linux.
  688.  
  689.    Linux is in the process of switching over to the GNU C library,
  690. version 2, which will become Linux libc version 6.  Once this process is
  691. complete, there's a good chance that the installation process on Linux
  692. will be smoother, but only experts should try making this new library
  693. work at this point.
  694.  
  695. Problems with g++ on Linux Slackware 3.0
  696. ========================================
  697.  
  698.    "When I try to compile the traditional Hello, world program on Linux,
  699. the compiler can't find `iostream.h'.  What's the deal?"
  700.  
  701.    You probably have the Slackware 3.0 release.  There's an error in the
  702. setup.  It's easy to fix, though; log in as root, and make a symbolic
  703. link:
  704.  
  705.      ln -s /usr/lib/g++-include /usr/include/g++
  706.  
  707. The Evolution of g++
  708. ********************
  709.  
  710.    This chapter discusses the evolution of g++ and describes what can
  711. be expected in the future.
  712.  
  713. What's new in version 2.7.x of gcc/g++
  714. ======================================
  715.  
  716.    The current version of gcc/g++ is 2.7.2.2, released February 10,
  717. 1997.  The only change between 2.7.2.1 and 2.7.2.2 is that support was
  718. added for using the GNU C library, version 2, on Linux; users not
  719. interested in that functionality have no reason to upgrade.  The
  720. previous version of gcc/g++ is 2.7.2.1, released August 14, 1996.  The
  721. current version of libg++ is 2.7.2, released July 4, 1996.
  722.  
  723.    Note that gcc 2.7.2.1 just consists of several small patches to
  724. gcc-2.7.2.  The release is mainly intended to fix platform-specific
  725. bugs and does not affect the C++ "front end" of the compiler (the part
  726. that parses your C++ code).
  727.  
  728.    The 2.7.x releases represent a great deal of work on the part of the
  729. g++ maintainers to fix outstanding bugs and move the compiler closer to
  730. the current ANSI/ISO standards committee's working paper, including
  731. supporting many of the new features that have been added to the
  732. language.  I recommend that everyone read the NEWS file contained in the
  733. distribution (and that system administrators make the file available to
  734. their users).  I've borrowed liberally from this file here.
  735.  
  736.    If any features seem unfamiliar, you will probably want to look at
  737. the recently-released public review copy of the C++ Working Paper.  A
  738. new draft, dated 2 December 1996, has been released for public comment.
  739. You can find it on the web at `http://www.cygnus.com/misc/wp/' or
  740. `http://www.maths.warwick.ac.uk/c++/pub/wp/html/cd2/'.  See
  741. `http://www.setech.com/x3.html' or
  742. `http://www.maths.warwick.ac.uk/c++/pub/' to download the document in
  743. PostScript, PDF (Adobe Acrobat), HTML, or ASCII form.
  744.  
  745.    Here are the main points:
  746.  
  747.    * As described above, the scope of variables declared in the
  748.      initialization part of a for statement has been changed; such
  749.      variables are now visible only in the loop body.  Use
  750.      `-fno-for-scope' to get the old behavior.  You'll need this flag
  751.      to build groff version 1.09, Ptolemy, and many other free software
  752.      packages.
  753.  
  754.    * Code that does not use #pragma interface/implementation will most
  755.      likely shrink dramatically, as g++ now only emits the vtable for a
  756.      class in the translation unit where its first non-inline,
  757.      non-abstract virtual function is defined.
  758.  
  759.    * Support for automatic template instantiation has *not* been enabled
  760.      in the official distribution, due to a disagreement over design
  761.      philosophies.  But you can get a patch from Cygnus to turn it on;
  762.      retrieve the patch from
  763.      `ftp://ftp.cygnus.com/pub/g++/gcc-2.7.2-repo.gz' to patch
  764.      gcc-2.7.2 (there are also patches for earlier gcc versions).
  765.  
  766.    * *Note exceptions::
  767.  
  768.    * Support for Run-Time Type Identification has been added with
  769.      `-frtti'.  This support is still in alpha; one major restriction
  770.      is that any file compiled with `-frtti' must include `<typeinfo>'
  771.      (*not* `typeinfo.h' as the NEWS file says).  Also, all C++ code
  772.      you link with (including libg++) has to be built with `-frtti', so
  773.      it's still tricky to use.
  774.  
  775.    * Synthesis of compiler-generated constructors, destructors and
  776.      assignment operators is now deferred until the functions are used.
  777.  
  778.    * The parsing of expressions such as `a ? b : c = 1' has changed from
  779.      `(a ? b : c) = 1' to `a ? b : (c = 1)'.  This is a new C/C++
  780.      incompatibility brought to you by the ANSI/ISO standards committee.
  781.  
  782.    * The operator keywords and, and_eq, bitand, bitor, compl, not,
  783.      not_eq, or, or_eq, xor and xor_eq are now supported.  Use `-ansi'
  784.      or `-foperator-names' to enable them.
  785.  
  786.    * The `explicit' keyword is now supported.  `explicit' is used to
  787.      mark constructors and type conversion operators that should not be
  788.      used implicitly.
  789.  
  790.    * Handling of user-defined type conversion has been improved.
  791.  
  792.    * Explicit instantiation of template methods is now supported.  Also,
  793.      `inline template class foo<int>;' can be used to emit only the
  794.      vtable for a template class.
  795.  
  796.    * With -fcheck-new, g++ will check the return value of all calls to
  797.      operator new, and not attempt to modify a returned null pointer.
  798.  
  799.    * collect2 now demangles linker output, and c++filt has become part
  800.      of the gcc distribution.
  801.  
  802.    * Improvements to template instantiation: only members actually used
  803.      are instantiated.  (Actually this is not quite true: some inline
  804.      templates that are not successfully inlined may be expanded even
  805.      though they are not needed).
  806.  
  807. The GNU Standard C++ Library
  808. ============================
  809.  
  810.    The GNU Standard C++ Library (also called the "GNU ANSI C++ Library"
  811. in places in the code) is not libg++, though it is included in the
  812. libg++ distribution.  Rather, it contains classes and functions
  813. required by the ANSI/ISO standard.  The copyright conditions are the
  814. same as those for for the iostreams classes; the LGPL is not used
  815. (*note legalities::.).
  816.  
  817.    This library, libstdc++, is in the libg++ distribution in versions
  818. 2.6.2 and later.  It requires at least gcc 2.6.3 to build the
  819. libg++-2.6.2 version; use at least gcc 2.7.0 to build the libg++ 2.7.0
  820. version.  It contains a hacked-up version of HP's implementation of the
  821. Standard Template Library (*note Standard Template Library::.).  I've
  822. successfully used this Standard Template Library version to build a
  823. number of the demos you'll see on various web pages.
  824.  
  825.    As of version 2.7.0, the streams classes are now in libstdc++
  826. instead of libg++, and libiostream is being phased out (don't use it).
  827. The g++ program searches this library.
  828.  
  829.    The maintainers of libg++ have de-emphasized work on the older
  830. libg++ classes in favor of enhancing libstdc++ to cover the full
  831. language, so while libg++ will always be available, enhancements to it
  832. should not be expected.
  833.  
  834. What can we expect in future gcc releases?
  835. ==========================================
  836.  
  837.    A great deal of work has gone into enhancements to the C++ front
  838. end, as well as to other aspects of the compiler.
  839.  
  840.    The next major release(s) of gcc/g++ can be expected to have the
  841. following features:
  842.  
  843.    * A completely new template implementation, much closer to the draft
  844.      standard.  Limitations in 2.7.2.x concerning inlining template
  845.      functions will be eliminated.  Static template data members,
  846.      template class member functions, partial specification, and
  847.      default template arguments will be supported.  An instantiation
  848.      method resembling that used in Borland C++ (instantiating
  849.      functions possibly in multiple .o files and using weak symbols to
  850.      link correctly) will be provided, in addition to other options.
  851.      The SGI version of STL will be shipped with libstdc++ and will
  852.      compile unchanged.
  853.  
  854.    * Exception handling has been re-worked; exceptions will work
  855.      together with optimization.  Actually, there are two separate
  856.      implementations: one based on setjmp/longjmp and designed to be
  857.      highly portable, and one designed to be more efficient but
  858.      requiring more processor-specific support (getting exceptions
  859.      right has proven to be extremely difficult and has been the chief
  860.      obstacle to getting a new release out).
  861.  
  862.    * RTTI has been re-done to work correctly and is on by default.
  863.  
  864.    * Overloading has been re-worked to conform to the latest draft of
  865.      the standard.
  866.  
  867.    Features that are still missing include namespaces and templates as
  868. template arguments.
  869.  
  870. What's this I hear about egcs?
  871. ==============================
  872.  
  873.    The egcs effort is a new effort to merge several threads of gcc
  874. development and to provide a faster development process.  For more
  875. information see `http://www.cygnus.com/egcs/'.
  876.  
  877. OK, when can I get this stuff?
  878. ==============================
  879.  
  880.    The FSF has a policy of never announcing release dates in advance.
  881. I'm sure this is frustrating to a lot of people, since it's taken so
  882. long, and this frustration was one of the reasons the egcs effort was
  883. created.  An egcs release should be expected to occur in the very near
  884. future.   [ More on this next time ].
  885.  
  886. User Problems
  887. *************
  888.  
  889. Linker complains about missing virtual table
  890. ============================================
  891.  
  892.    "I'm getting a message complaining about an undefined virtual table.
  893. Is this a compiler bug?"
  894.  
  895.    (On platforms that run neither collect nor the GNU linker, like
  896. Solaris, you may see an odd undefined symbol like "_vt.3foo", where foo
  897. is a class name).
  898.  
  899.    This is probably because you are missing a definition for the first
  900. (non-inline) virtual function of the class.  Since gcc-2.7.0, g++ uses
  901. a trick borrowed from cfront: the .o file containing the definition for
  902. the first non-inline virtual function for the class will also contain
  903. the virtual function table.
  904.  
  905. gcc-2.7.0 breaks declarations in "for" statements!
  906. ==================================================
  907.  
  908.    gcc-2.7.0 implements the new ANSI/ISO rule on the scope of variables
  909. declared in for loops.
  910.  
  911.      for (int i = 1; i <= 10; i++) {
  912.              // do something here
  913.      }
  914.      foo(i);
  915.  
  916.    In the above example, most existing C++ compilers would pass the
  917. value 11 to the function `foo'.  In gcc 2.7 and in the ANSI/ISO working
  918. paper, the scope of `i' is only the for loop body, so this is an error.
  919. So that old code can be compiled, the new gcc has a flag
  920. `-fno-for-scope' that causes the old rule to be used.
  921.  
  922.    As of 2.7.1, the compiler attempts to issue warnings about code that
  923. has different meanings under the two sets of rules, but the code is not
  924. perfect: the intent was that code that has valid, but different,
  925. meanings under the ARM rules and the working paper rules would give
  926. warnings but have the new behavior, and this doesn't seem to happen.
  927.  
  928.    The `-ffor-scope' flag under 2.7.1 and 2.7.2 gives the 2.7.0
  929. behavior.
  930.  
  931. g++ seems to want a const constructor.  What's that?
  932. ====================================================
  933.  
  934.    gcc-2.7.1 introduced a bug that causes the compiler to ask for a
  935. const constructor (there's no such thing in C++) in certain situations
  936. where a const object appears in a template class.  Most cases have been
  937. fixed in gcc-2.7.2, but unfortunately not all.  Still, if you're running
  938. gcc-2.7.1 and have this problem, upgrade to 2.7.2; it is a vast
  939. improvement.
  940.  
  941.    The default constructor for the template `pair' in ObjectSpace's
  942. implementation of STL triggers the bug in one place, for gcc 2.7.2.  If
  943. you're using ObjectSpace<STL> and having this problem, simply change
  944. the default constructor from
  945.  
  946.      os_pair () : first (T1 ()), second (T2 ()) {}
  947.  
  948.    to just
  949.  
  950.      os_pair () {}
  951.  
  952.    Once this is done, ObjectSpace<STL> works fairly well.
  953.  
  954. How to silence "unused parameter" warnings
  955. ==========================================
  956.  
  957.    "When I use `-Wall' (or `-Wunused'), g++ warns about unused
  958. parameters.  But the parameters have to be there, for use in derived
  959. class functions.  How do I get g++ to stop complaining?"
  960.  
  961.    The answer is to simply omit the names of the unused parameters when
  962. defining the function.  This makes clear, both to g++ and to readers of
  963. your code, that the parameter is unused.  For example:
  964.  
  965.      int Foo::bar(int arg) { return 0; }
  966.  
  967.    will give a warning for the unused parameter `arg'.  To suppress the
  968. warning write
  969.  
  970.      int Foo::bar(int) { return 0; }
  971.  
  972. g++ objects to a declaration in a case statement
  973. ================================================
  974.  
  975.    "The compiler objects to my declaring a variable in one of the
  976. branches of a case statement.  Earlier versions used to accept this
  977. code.  Why?"
  978.  
  979.    The draft standard does not allow a goto or a jump to a case label to
  980. skip over an initialization of a variable or a class object.  For
  981. example:
  982.  
  983.      switch ( i ) {
  984.        case 1:
  985.          Object obj(0);
  986.              ...
  987.          break;
  988.        case 2:
  989.          ...
  990.          break;
  991.      }
  992.  
  993.    The reason is that `obj' is also in scope in the rest of the switch
  994. statement.
  995.  
  996.    As of version 2.7.0, the compiler will object that the jump to the
  997. second case level crosses the initialization of `obj'.  Older compiler
  998. versions would object only if class Object has a destructor.  In either
  999. case, the solution is to add a set of curly braces around the case
  1000. branch:
  1001.  
  1002.        case 1:
  1003.          {
  1004.             Object obj(0);
  1005.              ...
  1006.             break;
  1007.          }
  1008.  
  1009. Where can I find a demangler?
  1010. =============================
  1011.  
  1012.    A g++-compatible demangler named `c++filt' can be found in the
  1013. `binutils' distribution.  This distribution (which also contains the
  1014. GNU linker) can be found at any GNU archive site.
  1015.  
  1016.    As of version 2.7.0, `c++filt' is included with gcc and is installed
  1017. automatically.  Even better, it is used by the `collect' linker, so you
  1018. don't see mangled symbols anymore (except on platforms that use neither
  1019. collect nor the GNU linker, like Solaris).
  1020.  
  1021. Linker reports undefined symbols for static data members
  1022. ========================================================
  1023.  
  1024.    "g++ reports undefined symbols for all my static data members when I
  1025. link, even though the program works correctly for compiler XYZ.  What's
  1026. going on?"
  1027.  
  1028.    The problem is almost certainly that you don't give definitions for
  1029. your static data members.  If you have
  1030.  
  1031.      class Foo {
  1032.          ...
  1033.          void method();
  1034.          static int bar;
  1035.      };
  1036.  
  1037.    you have only declared that there is an int named Foo::bar and a
  1038. member function named Foo::method that is defined somewhere.  You still
  1039. need to define *both* method() and bar in some source file.  According
  1040. to the draft ANSI standard, you must supply an initializer, such as
  1041.  
  1042.      int Foo::bar = 0;
  1043.  
  1044. in one (and only one) source file.
  1045.  
  1046. What does "Internal compiler error" mean?
  1047. =========================================
  1048.  
  1049.    It means that the compiler has detected a bug in itself.
  1050. Unfortunately, g++ still has many bugs, though it is a lot better than
  1051. it used to be.  If you see this message, please send in a complete bug
  1052. report (see next section).
  1053.  
  1054. I think I have found a bug in g++.
  1055. ==================================
  1056.  
  1057.    "I think I have found a bug in g++, but I'm not sure.  How do I know,
  1058. and who should I tell?"
  1059.  
  1060.    First, see the excellent section on bugs and bug reports in the gcc
  1061. manual (which is included in the gcc distribution).  As a short summary
  1062. of that section: if the compiler gets a fatal signal, for any input,
  1063. it's a bug (newer versions of g++ will ask you to send in a bug report
  1064. when they detect an error in themselves).  Same thing for producing
  1065. invalid assembly code.
  1066.  
  1067.    When you report a bug, make sure to describe your platform (the type
  1068. of computer, and the version of the operating system it is running) and
  1069. the version of the compiler that you are running.  See the output of the
  1070. command `g++ -v' if you aren't sure.  Also provide enough code so that
  1071. the g++ maintainers can duplicate your bug.  Remember that the
  1072. maintainers won't have your header files; one possibility is to send
  1073. the output of the preprocessor (use `g++ -E' to get this).  This is
  1074. what a "complete bug report" means.
  1075.  
  1076.    I will add some extra notes that are C++-specific, since the notes
  1077. from the gcc documentation are generally C-specific.
  1078.  
  1079.    First, mail your bug report to "bug-g++@prep.ai.mit.edu".  You may
  1080. also post to `gnu.g++.bug', but it's better to use mail, particularly
  1081. if you have any doubt as to whether your news software generates
  1082. correct reply addresses.  Don't mail C++ bugs to
  1083. bug-gcc@prep.ai.mit.edu.
  1084.  
  1085.    *News:* as I write this (late February 1996) the gateway connecting
  1086. the bug-g++ mailing list and the `gnu.g++.bug' newsgroup is
  1087. (temporarily?) broken.  Please mail, do not post bug reports.
  1088.  
  1089.    If your bug involves libg++ rather than the compiler, mail to
  1090. bug-lib-g++@prep.ai.mit.edu.  If you're not sure, choose one, and if you
  1091. guessed wrong, the maintainers will forward it to the other list.
  1092.  
  1093.    Second, if your program does one thing, and you think it should do
  1094. something else, it is best to consult a good reference if in doubt.
  1095. The standard reference is the draft working paper from the ANSI/ISO C++
  1096. standardization committee, which you can get on the net.  For
  1097. PostScript and PDF (Adobe Acrobat) versions, see the archive at
  1098. `ftp://research.att.com/dist/stdc++/WP'.  For HTML and ASCII versions,
  1099. see `ftp://ftp.cygnus.com/pub/g++'.  On the World Wide Web, see
  1100. `http://www.cygnus.com/misc/wp/'.
  1101.  
  1102.    An older standard reference is "The Annotated C++ Reference Manual",
  1103. by Ellis and Stroustrup (copyright 1990, ISBN #0-201-51459-1).  This is
  1104. what they're talking about on the net when they refer to "the ARM".
  1105. But you should know that changes have been made to the language since
  1106. then.
  1107.  
  1108.    The ANSI/ISO C++ standards committee have adopted some changes to the
  1109. C++ language since the publication of the original ARM, and newer
  1110. versions of g++ (2.5.x and later) support some of these changes, notably
  1111. the mutable keyword (added in 2.5.0), the bool type (added in 2.6.0),
  1112. and changes in the scope of variables defined in for statements (added
  1113. in 2.7.0).  You can obtain an addendum to the ARM explaining many of
  1114. these changes by FTP from
  1115. `ftp://ftp.std.com/AW/stroustrup2e/new_iso.ps'.
  1116.  
  1117.    Note that the behavior of (any version of) AT&T's "cfront" compiler
  1118. is NOT the standard for the language.
  1119.  
  1120. Porting programs from other compilers to g++
  1121. ============================================
  1122.  
  1123.    "I have a program that runs on <some other C++ compiler>, and I want
  1124. to get it running under g++.  Is there anything I should watch out for?"
  1125.  
  1126.    Note that g++ supports many of the newer keywords that have recently
  1127. been added to the language.  Your other C++ compiler may not support
  1128. them, so you may need to rename variables and members that conflict
  1129. with these keywords.
  1130.  
  1131.    There are two other reasons why a program that worked under one
  1132. compiler might fail under another: your program may depend on the order
  1133. of evaluation of side effects in an expression, or it may depend on the
  1134. lifetime of a temporary (you may be assuming that a temporary object
  1135. "lives" longer than the standard guarantees).  As an example of the
  1136. first:
  1137.  
  1138.      void func(int,int);
  1139.      
  1140.      int i = 3;
  1141.      func(i++,i++);
  1142.  
  1143.    Novice programmers think that the increments will be evaluated in
  1144. strict left-to-right order.  Neither C nor C++ guarantees this; the
  1145. second increment might happen first, for example.  func might get 3,4,
  1146. or it might get 4,3.
  1147.  
  1148.    The second problem often happens with classes like the libg++ String
  1149. class.  Let's say I have
  1150.  
  1151.      String func1();
  1152.      void func2(const char*);
  1153.  
  1154.    and I say
  1155.  
  1156.      func2(func1());
  1157.  
  1158.    because I know that class String has an "operator const char*".  So
  1159. what really happens is
  1160.  
  1161.      func2(func1().convert());
  1162.  
  1163.    where I'm pretending I have a convert() method that is the same as
  1164. the cast.  This is unsafe in g++ versions before 2.6.0, because the
  1165. temporary String object may be deleted after its last use (the call to
  1166. the conversion function), leaving the pointer pointing to garbage, so by
  1167. the time func2 is called, it gets an invalid argument.
  1168.  
  1169.    Both the cfront and the old g++ behaviors are legal according to the
  1170. ARM, but the powers that be have decided that compiler writers were
  1171. given too much freedom here.
  1172.  
  1173.    The ANSI C++ committee has now come to a resolution of the lifetime
  1174. of temporaries problem: they specify that temporaries should be deleted
  1175. at end-of-statement (and at a couple of other points).  This means that
  1176. g++ versions before 2.6.0 now delete temporaries too early, and cfront
  1177. deletes temporaries too late.  As of version 2.6.0, g++ does things
  1178. according to the new standard.
  1179.  
  1180.    For now, the safe way to write such code is to give the temporary a
  1181. name, which forces it to live until the end of the scope of the name.
  1182. For example:
  1183.  
  1184.      String& tmp = func1();
  1185.      func2(tmp);
  1186.  
  1187.    Finally, like all compilers (but especially C++ compilers, it seems),
  1188. g++ has bugs, and you may have tweaked one.  If so, please file a bug
  1189. report (after checking the above issues).
  1190.  
  1191. Why does g++ mangle names differently from other C++ compilers?
  1192. ===============================================================
  1193.  
  1194.    See the answer to the next question.
  1195.  
  1196. Why can't g++ code link with code from other C++ compilers?
  1197. ===========================================================
  1198.  
  1199.    "Why can't I link g++-compiled programs against libraries compiled by
  1200. some other C++ compiler?"
  1201.  
  1202.    Some people think that, if only the FSF and Cygnus Support folks
  1203. would stop being stubborn and mangle names the same way that, say,
  1204. cfront does, then any g++-compiled program would link successfully
  1205. against any cfront-compiled library and vice versa.  Name mangling is
  1206. the least of the problems.  Compilers differ as to how objects are laid
  1207. out, how multiple inheritance is implemented, how virtual function
  1208. calls are handled, and so on, so if the name mangling were made the
  1209. same, your programs would link against libraries provided from other
  1210. compilers but then crash when run.  For this reason, the ARM
  1211. *encourages* compiler writers to make their name mangling different
  1212. from that of other compilers for the same platform.  Incompatible
  1213. libraries are then detected at link time, rather than at run time.
  1214.  
  1215. What documentation exists for g++ 2.x?
  1216. ======================================
  1217.  
  1218.    Relatively little.  While the gcc manual that comes with the
  1219. distribution has some coverage of the C++ part of the compiler, it
  1220. focuses mainly on the C compiler (though the information on the "back
  1221. end" pertains to C++ as well).  Still, there is useful information on
  1222. the command line options and the #pragma interface and #pragma
  1223. implementation directives in the manual, and there is a useful section
  1224. on template instantiation in the 2.6 version.  There is a Unix-style
  1225. manual entry, "g++.1", in the gcc-2.x distribution; the information
  1226. here is a subset of what is in the manual.
  1227.  
  1228.    You can buy a nicely printed and bound copy of this manual from the
  1229. FSF; see above for ordering information.
  1230.  
  1231.    A draft of a document describing the g++ internals appears in the gcc
  1232. distribution (called g++int.texi); it is incomplete but gives lots of
  1233. information.
  1234.  
  1235.    For class libraries, there are several resources available:
  1236.  
  1237.    * The libg++ distribution has a manual `libg++/libg++.texi'
  1238.      describing the old libg++ classes, and another manual
  1239.      `libio/iostream.texi' describing the iostreams implementation.
  1240.  
  1241.    * While there is no libg++-specific document describing the STL
  1242.      implementation, SGI's web site, at
  1243.      `http://www.sgi.com/Technology/STL/', is an excellent resource.
  1244.  
  1245. Problems with the template implementation
  1246. =========================================
  1247.  
  1248.    g++ does not implement a separate pass to instantiate template
  1249. functions and classes at this point; for this reason, it will not work,
  1250. for the most part, to declare your template functions in one file and
  1251. define them in another.  The compiler will need to see the entire
  1252. definition of the function, and will generate a static copy of the
  1253. function in each file in which it is used.
  1254.  
  1255.    (The experimental template repository code (*note repository::.) that
  1256. can be added to 2.7.0 or later does implement a separate pass, but there
  1257. is still no searching of files that the compiler never saw).
  1258.  
  1259.    For version 2.6.0, however, a new switch `-fno-implicit-templates'
  1260. was added; with this switch, templates are expanded only under user
  1261. control.  I recommend that all g++ users that use templates read the
  1262. section "Template Instantiation" in the gcc manual (version 2.6.x and
  1263. newer).  g++ now supports explicit template expansion using the syntax
  1264. from the latest C++ working paper:
  1265.  
  1266.      template class A<int>;
  1267.      template ostream& operator << (ostream&, const A<int>&);
  1268.  
  1269.    As of version 2.6.3, there are still a few limitations in the
  1270. template implementation besides the above (thanks to Jason Merrill for
  1271. this info): These are still present in version 2.7.2, but a new
  1272. implementation of templates planned for version 2.8 will eliminate them.
  1273.  
  1274.   1. Static data member templates are not supported.  You can work
  1275.      around this by explicitly declaring the static variable for each
  1276.      template specialization:
  1277.  
  1278.           template <class T> struct A {
  1279.             static T t;
  1280.           };
  1281.           
  1282.           template <class T> T A<T>::t = 0; // gets bogus error
  1283.           int A<int>::t = 0;                // OK (workaround)
  1284.  
  1285.      (still a limitation in 2.7.2)
  1286.  
  1287.   2. Template member names are not available when defining member
  1288.      function templates.
  1289.  
  1290.           template <class T> struct A {
  1291.             typedef T foo;
  1292.             void f (foo);
  1293.             void g (foo arg) { ... }; // this works
  1294.           };
  1295.           
  1296.           template <class T> void A<T>::f (foo) { } // gets bogus error
  1297.  
  1298.   3. Templates are instantiated using the parser.  This results in two
  1299.      problems:
  1300.  
  1301.      a) Class templates are instantiated in some situations where such
  1302.      instantiation should not occur.
  1303.  
  1304.           template <class T> class A { };
  1305.           A<int> *aip = 0; // should not instantiate A<int> (but does)
  1306.  
  1307.      b) Function templates cannot be inlined at the site of their
  1308.      instantiation.
  1309.  
  1310.           template <class T> inline T min (T a, T b) { return a < b ? a : b; }
  1311.           
  1312.           void f () {
  1313.             int i = min (1, 0);           // not inlined
  1314.           }
  1315.           
  1316.           void g () {
  1317.             int j = min (1, 0);           // inlined
  1318.           }
  1319.  
  1320.      A workaround that works in version 2.6.1 and later is to specify
  1321.  
  1322.           extern template int min (int, int);
  1323.  
  1324.      before `f()'; this will force it to be instantiated (though not
  1325.      emitted).
  1326.  
  1327.   4. Member function templates are always instantiated when their
  1328.      containing class is.  This is wrong.
  1329.  
  1330. I get undefined symbols when using templates
  1331. ============================================
  1332.  
  1333.    (Thanks to Jason Merrill for this section).
  1334.  
  1335.    g++ does not automatically instantiate templates defined in other
  1336. files.  Because of this, code written for cfront will often produce
  1337. undefined symbol errors when compiled with g++.  You need to tell g++
  1338. which template instances you want, by explicitly instantiating them in
  1339. the file where they are defined.  For instance, given the files
  1340.  
  1341.    `templates.h':
  1342.      template <class T>
  1343.      class A {
  1344.      public:
  1345.        void f ();
  1346.        T t;
  1347.      };
  1348.      
  1349.      template <class T> void g (T a);
  1350.  
  1351.    `templates.cc':
  1352.      #include "templates.h"
  1353.      
  1354.      template <class T>
  1355.      void A<T>::f () { }
  1356.      
  1357.      template <class T>
  1358.      void g (T a) { }
  1359.  
  1360.    main.cc:
  1361.      #include "templates.h"
  1362.      
  1363.      main ()
  1364.      {
  1365.        A<int> a;
  1366.        a.f ();
  1367.        g (a);
  1368.      }
  1369.  
  1370.    compiling everything with `g++ main.cc templates.cc' will result in
  1371. undefined symbol errors for `A<int>::f ()' and `g (A<int>)'.  To fix
  1372. these errors, add the lines
  1373.  
  1374.      template class A<int>;
  1375.      template void g (A<int>);
  1376.  
  1377.    to the bottom of `templates.cc' and recompile.
  1378.  
  1379. I get multiply defined symbols using templates
  1380. ==============================================
  1381.  
  1382.    You may be running into a bug that was introduced in version 2.6.1
  1383. (and is still present in 2.6.3) that generated external linkage for
  1384. templates even when neither `-fexternal-templates' nor
  1385. `-fno-implicit-templates' is specified.  There is a patch for this
  1386. problem at
  1387. `ftp://ftp.cygnus.com/pub/g++/gcc-2.6.3-template-fix'.
  1388.  
  1389.    I recommend either applying the patch or using
  1390. `-fno-implicit-templates' together with explicit template instantiation
  1391. as described in previous sections.
  1392.  
  1393.    This bug is fixed in 2.7.0.
  1394.  
  1395. Does g++ support the Standard Template Library?
  1396. ===============================================
  1397.  
  1398.    The Standard Template Library (STL) uses many of the extensions that
  1399. the ANSI/ISO committee has made to templates, and g++ doesn't support
  1400. some of these yet.  So if you grab HP's free implementation of STL it
  1401. isn't going to work.  However, starting with libg++-2.6.2 libg++
  1402. contains a hacked version of STL, based on work by Carsten Bormann,
  1403. which permits g++ to compile at least the containers (thanks to Per
  1404. Bothner for this text).
  1405.  
  1406.    Actually, as of libg++ version 2.7.2 most of this works quite well,
  1407. most of the time; I've succeeded in making significant use of it.
  1408. Almost all of the ObjectSpace examples (a set of over 200 simple
  1409. examples of STL usage) now work.
  1410.  
  1411.    When version 2.8.0 is out (with its complete redesign of the template
  1412. implementation) a much more complete implementation of the STL (based
  1413. on a newer free implementation from SGI) will be included.  In the
  1414. meantime, a group at the Moscow Center for Sparc Technology has a port
  1415. of the SGI STL implementation that mostly works with gcc-2.7.2.  See
  1416. `http://www.ipmce.su/people/fbp/stl/stlport.html'.
  1417.  
  1418.    In addition, there are several commercial suppliers of STL
  1419. implementations; ObjectSpace's version supports gcc-2.7.x.
  1420.  
  1421.    Mumit Khan has produced an "STL newbie guide" with lots of
  1422. information on using STL with gcc.  See
  1423.  
  1424.    `http://www.xraylith.wisc.edu/~khan/software/stl/STL.newbie.html'
  1425.  
  1426. I'm having problems mixing STL and the standard string class
  1427. ============================================================
  1428.  
  1429.    This is due to a bug in g++ version 2.7.2 and 2.7.2.1; the compiler
  1430. is confused by the operator declarations.  There is an easy workaround,
  1431. however; just make sure that the `<string>' header is included before
  1432. any STL headers.  That is, just say
  1433.  
  1434.      #include <string>
  1435.  
  1436.    before any other `#include' directives.
  1437.  
  1438.    Unfortunately, this doesn't solve all problems; you may still have
  1439. difficulty with the relational operators !=, <=, >, and >=, thanks to a
  1440. conflict with the very general definition of these operators in
  1441. function.h.  One trick that sometimes works is to try to use == and <
  1442. in your code instead of the other operators.  Another is to use a
  1443. derived class of <string>.  The only completely satisfactory solution,
  1444. I'm afraid, is to wait for the new release.
  1445.  
  1446. Problems and limitations with exceptions
  1447. ========================================
  1448.  
  1449.    Recent g++ versions provide limited support for exceptions.  You must
  1450. provide the `-fhandle-exceptions' flag to enable exception handling.
  1451. As of version 2.7.2, exceptions may not work properly (and you may get
  1452. odd error messages when compiling) if you turn on optimization (the
  1453. `-O' flag).
  1454.  
  1455.    You must give the `-frtti' switch to enable catching of derived
  1456. exception objects with handlers for the base exception class; if
  1457. `-frtti' is not given, only exact type matching works.
  1458.  
  1459.    For exception handling to work with 2.7.0 your CPU must be a SPARC,
  1460. RS6000/PowerPC, 386/486/Pentium, or ARM.  Release 2.7.1 added support
  1461. for the Alpha, and "m68k is rumored to work on some platforms" and "VAX
  1462. may also work" (according to Mike Stump).  *It still doesn't work on
  1463. HP-PA or MIPS platforms.*
  1464.  
  1465. Does g++ support namespaces?
  1466. ============================
  1467.  
  1468.    As of version 2.7.2, g++ recognizes the keywords `namespace' and
  1469. `using', and there is some rudimentary code present, but almost nothing
  1470. connected with namespaces works yet.  It appears that this will still
  1471. be true when 2.8.0 is released.
  1472.  
  1473. What are the differences between g++ and the ARM specification of C++?
  1474. ======================================================================
  1475.  
  1476.    As of version 2.7.0, g++ has exception support on most but not all
  1477. platforms (no support on MIPS-based platforms yet), but it doesn't work
  1478. right if optimizaton is enabled, which means the exception
  1479. implementation is still not really ready for production use.
  1480.  
  1481.    Some features that the ANSI/ISO standardization committee has voted
  1482. in that don't appear in the ARM are supported, notably the `mutable'
  1483. keyword, in version 2.5.x.  2.6.x adds support for the built-in boolean
  1484. type `bool', with constants `true' and `false'.  The beginnings of
  1485. run-time type identification are present, so there are more reserved
  1486. words: `typeid', `static_cast', `reinterpret_cast', `const_cast', and
  1487. `dynamic_cast'.
  1488.  
  1489.    As with any beta-test compiler, there are bugs.  You can help improve
  1490. the compiler by submitting detailed bug reports.
  1491.  
  1492.    One of the weakest areas of g++ other than templates is the
  1493. resolution of overloaded functions and operators in complex cases.  The
  1494. usual symptom is that in a case where the ARM says that it is ambiguous
  1495. which function should be chosen, g++ chooses one (often the first one
  1496. declared).  This is usually not a problem when porting C++ code from
  1497. other compilers to g++, but shows up as errors when code developed under
  1498. g++ is ported to other compilers.  (I believe this is no longer a
  1499. significant problem in 2.7.0).
  1500.  
  1501.    [A full bug list would be very long indeed, so I won't put one here.
  1502. I may add a list of frequently-reported bugs and "non-bugs" like the
  1503. static class members issue mentioned above].
  1504.  
  1505. Will g++ compile InterViews?  The NIH class library?  Rogue Wave?
  1506. =================================================================
  1507.  
  1508.    The NIH class library uses a non-portable, compiler-dependent hack
  1509. to initialize itself, which makes life difficult for g++ users.  It
  1510. will not work without modification, and I don't know what modifications
  1511. are required or whether anyone has done them successfully.
  1512.  
  1513.    In short, it's not going to happen any time soon (previous FAQs
  1514. referred to patches that a new NIHCL release would hopefully contain,
  1515. but this hasn't happened).
  1516.  
  1517.    *Note:* I thought I saw an item indicating that someone *had*
  1518. patched NIHCL to work with g++.  Any pointers?
  1519.  
  1520.    I think that as of version 2.5.6, the standard g++ will compile the
  1521. standard 3.1 InterViews completely successfully.  Note that you'll need
  1522. the `-fno-for-scope' flag if you use gcc-2.7.0; with 2.7.2 you may be
  1523. able to omit this flag but you'll get warnings.
  1524.  
  1525.    According to Jason Merrill, gcc-2.7.0 and newer works with Rogue
  1526. Wave's `tools.h++' class library, but you may want to grab
  1527. `ftp://ftp.cygnus.com/pub/g++/Tools.h++-6.1-patch'.  Again, you'll need
  1528. the `-fno-for-scope' flag since Rogue Wave hasn't fixed their code to
  1529. comply with the new standard yet.
  1530.  
  1531. Debugging on SVR4 systems
  1532. =========================
  1533.  
  1534.    "How do I get debugging to work on my System V Release 4 system?"
  1535.  
  1536.    Most systems based on System V Release 4 (except Solaris) encode
  1537. symbolic debugging information in a format known as `DWARF'.
  1538.  
  1539.    Although the GNU C compiler already knows how to write out symbolic
  1540. debugging information in the DWARF format, the GNU C++ compiler does
  1541. not yet have this feature yet.  However, work is in progress for DWARF
  1542. 2 debug support for gcc and g++ and will be available in a future
  1543. release (probably 2.8.0).
  1544.  
  1545.    In the meantime, you *can* get g++ debugging under SVR4 systems by
  1546. configuring gcc with the `--with-stabs' option.  This causes gcc to use
  1547. an alternate debugging format, one more like that used under SunOS4.
  1548. You won't need to do anything special to GDB; it will always understand
  1549. the "stabs" format.
  1550.  
  1551. debugging problems on Solaris
  1552. =============================
  1553.  
  1554.    "I'm on Solaris, and gdb says it doesn't know about some of my local
  1555. symbols.  Help!"
  1556.  
  1557.    This problem was introduced in gcc 2.7.2; debug symbols for locals
  1558. that aren't declared at the beginning of a block come out in the wrong
  1559. order, and gdb can't find such symbols.
  1560.  
  1561.    This problem is fixed in gcc-2.7.2.1.
  1562.  
  1563. X11 conflicts with libg++ in definition of String
  1564. =================================================
  1565.  
  1566.    "X11 and Motif define String, and this conflicts with the String
  1567. class in libg++.  How can I use both together?"
  1568.  
  1569.    One possible method is the following:
  1570.  
  1571.      #define String XString
  1572.      #include <X11/Intrinsic.h>
  1573.      /* include other X11 and Motif headers */
  1574.      #undef String
  1575.  
  1576.    and remember to use the correct `String' or `XString' when you
  1577. declare things later.
  1578.  
  1579. Why can't I assign one stream to another?
  1580. =========================================
  1581.  
  1582.    [ Thanks to Per Bothner and Jerry Schwarz for this section. ]
  1583.  
  1584.    Assigning one stream to another seems like a reasonable thing to do,
  1585. but it's a bad idea.  Usually, this comes up because people want to
  1586. assign to `cout'.  This is poor style, especially for libraries, and is
  1587. contrary to good object-oriented design.  (Libraries that write directly
  1588. to `cout' are less flexible, modular, and object-oriented).
  1589.  
  1590.    The iostream classes do not allow assigning to arbitrary streams,
  1591. because this can violate typing:
  1592.  
  1593.      ifstream foo ("foo");
  1594.      istrstream str(...);
  1595.      foo = str;
  1596.      foo->close ();  /* Oops! Not defined for istrstream! */
  1597.  
  1598.    The original cfront implementation of iostreams by Jerry Schwarz
  1599. allows you to assign to `cin', `cout', `cerr', and `clog', but this is
  1600. not part of the draft standard for iostreams and generally isn't
  1601. considered a good idea, so standard-conforming code shouldn't use this
  1602. technique.
  1603.  
  1604.    The GNU implementation of iostream did not support assigning to
  1605. `cin', `cout', `cerr', and `clog' for quite a while, but it now does,
  1606. for backward compatibility with cfront iostream (versions 2.6.1 and
  1607. later of libg++).
  1608.  
  1609.    The ANSI/ISO C++ Working Paper does provide ways of changing the
  1610. streambuf associated with a stream.  Assignment isn't allowed; there is
  1611. an explicit named member that must be used.
  1612.  
  1613.    However, it is not wise to do this, and the results are confusing.
  1614. For example: `fstream::rdbuf' is supposed to return the *original*
  1615. filebuf, not the one you assigned. (This is not yet implemented in GNU
  1616. iostream.)  This must be so because `fstream::rdbuf' is defined to
  1617. return a `filebuf *'.
  1618.  
  1619. What are the rules for shipping code built with g++ and libg++?
  1620. ***************************************************************
  1621.  
  1622.    "Is it is possible to distribute programs for profit that are created
  1623. with g++ and use the g++ libraries?"
  1624.  
  1625.    I am not a lawyer, and this is not legal advice.  In any case, I have
  1626. little interest in telling people how to violate the spirit of the GNU
  1627. licenses without violating the letter.  This section tells you how to
  1628. comply with the intention of the GNU licenses as best I understand them.
  1629.  
  1630.    The FSF has no objection to your making money.  Its only interest is
  1631. that source code to their programs, and libraries, and to modified
  1632. versions of their programs and libraries, is always available.
  1633.  
  1634.    The short answer is that you do not need to release the source to
  1635. your program, but you can't just ship a stripped executable either,
  1636. unless you use only the subset of libg++ that includes the iostreams
  1637. classes (see discussion below) or the new libstdc++ library (available
  1638. in libg++ 2.6.2 and later).
  1639.  
  1640.    Compiling your code with a GNU compiler does not affect its
  1641. copyright; it is still yours.  However, in order to ship code that
  1642. links in a GNU library such as libg++ there are certain rules you must
  1643. follow.  The rules are described in the file COPYING.LIB that
  1644. accompanies gcc distributions; it is also included in the libg++
  1645. distribution.  See that file for the exact rules.  The agreement is
  1646. called the Library GNU Public License or LGPL.  It is much "looser"
  1647. than the GNU Public License, or GPL, that covers must GNU programs.
  1648.  
  1649.    Here's the deal: let's say that you use some version of libg++,
  1650. completely unchanged, in your software, and you want to ship only a
  1651. binary form of your code.  You can do this, but there are several
  1652. special requirements.  If you want to use libg++ but ship only object
  1653. code for your code, you have to ship source for libg++ (or ensure
  1654. somehow that your customer already has the source for the exact version
  1655. you are using), and ship your application in linkable form.  You cannot
  1656. forbid your customer from reverse-engineering or extending your program
  1657. by exploiting its linkable form.
  1658.  
  1659.    Furthermore, if you modify libg++ itself, you must provide source
  1660. for your modifications (making a derived class does not count as
  1661. modifying the library - that is "a work that uses the library").
  1662.  
  1663.    For certain portions of libg++ that implement required parts of the
  1664. C++ language (such as iostreams and other standard classes), the FSF has
  1665. loosened the copyright requirement still more by adding the "special
  1666. exception" clause, which reads as follows:
  1667.  
  1668.      As a special exception, if you link this library with files
  1669.      compiled with GCC to produce an executable, this does not cause
  1670.      the resulting executable to be covered by the GNU General Public
  1671.      License.  This exception does not however invalidate any other
  1672.      reasons why the executable file might be covered by the GNU
  1673.      General Public License.
  1674.  
  1675.    If your only use of libg++ uses code with this exception, you may
  1676. ship stripped executables or license your executables under different
  1677. conditions without fear of violating an FSF copyright.  It is the intent
  1678. of FSF and Cygnus that, as the other classes required by the ANSI/ISO
  1679. draft standard are developed, these will also be placed under this
  1680. "special exception" license.  The code in the new libstdc++ library,
  1681. intended to implement standard classes as defined by ANSI/ISO, is also
  1682. licensed this way.
  1683.  
  1684.    To avoid coming under the influence of the LGPL, you can link with
  1685. `-liostream' rather than `-lg++' (for version 2.6.x and earlier), or
  1686. `-lstdc++' now that it is available.  In version 2.7.0 all the standard
  1687. classes are in `-lstdc++'; you can do the link step with `c++' instead
  1688. of `g++' to search only the `-lstdc++' library and avoid the LGPL'ed
  1689. code in `-lg++'.
  1690.  
  1691.    If you wish to discuss legal issues connected with GNU software on
  1692. the net, please use `gnu.misc.discuss', not the technical newsgroups.
  1693.  
  1694. -- 
  1695. -- Joe Buck    http://www.synopsys.com/pubs/research/people/jbuck.html
  1696.  If you thought flashing ads on Web sites were annoying, wait till the Web
  1697.  and your operating system are "seamlessly integrated" and watch the
  1698.  pulsating promotional crud spill out over your desktop.  -- Scott Rosenburg
  1699.